import type { Request, Response, NextFunction } from "express";
import path from "path";
import { Server } from "socket.io";
function getUser(req: Request, res: Response, next: NextFunction) {
    let { id } = req.params;
    res.send({
        id,
        name: "李四",
    });
}

function allUsers(req: Request, res: Response, next: NextFunction) {
    let method = req.method;
    if (method === "GET") {
        return res.send({
            id: 5,
            name: "李四",
        });
    }
    if (method === "POST") {
        const io: Server = req.app.get("io");
        io.on("connection", (socket) => {
            console.log(socket.id); // 该客户端 id 可以给指定客户端发送消息
            socket.on("event", (data) => {
                /* … */
            });
            socket.on("disconnect", () => {
                /* … */
            });
        });
        return res.send("success");
    }
    res.redirect("/404");
}
export default {
    getUser,
    allUsers,
};
